package com.example.service;

import com.example.entity.Orders;
import com.example.entity.OrdersItem;
import com.example.mapper.OrdersItemMapper;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class OrdersItemService {

    @Resource
    private OrdersItemMapper ordersItemMapper;

    public void add(OrdersItem ordersItem) {
       ordersItemMapper.insert(ordersItem);
    }

    public PageInfo<OrdersItem> selectPage(OrdersItem ordersItem, Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum, pageSize);
        List<OrdersItem> list=ordersItemMapper.selectAll(ordersItem);
        return PageInfo.of(list);
    }
    public OrdersItem selectById(Integer id) {
        return ordersItemMapper.selectById(id);
    }
    public List<OrdersItem> selectAll(OrdersItem ordersItem) {
        List<OrdersItem> list=ordersItemMapper.selectAll(ordersItem);
        return list;
    }

    public void updateById(OrdersItem ordersItem) {
        ordersItemMapper.updateById(ordersItem);
    }

    public void deleteById(Integer id) {
        ordersItemMapper.deleteById(id);
    }

    public void deleteBatch(Integer[] ids) {
        for (Integer id : ids) {
            ordersItemMapper.deleteById(id);
        }
    }
    public List<OrdersItem> selectByOrderId(Integer id) {
        return ordersItemMapper.selectByOrderId(id);
    }

}
